#python版有问题
def create_txtx(filename,content,encode):
    file = open(filename,'w')
    file.write(encode+';'+content,encoding=encode)
    file.close()

def get_encode(filename):
    encode = []
    try:
        with open(filename, 'r') as file:
            while (p := file.read(1)) != ';':
                if not p:  # Check for EOF
                    break
                encode.append(p)
    except Exception as e:
        print(f"An error occurred: {e}")
        return None
    return ''.join(encode)
create_txtx('test.txtx','data','gbk')
print(get_encode('test.txtx'))